home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
gnu
/
gawk
/
gawk213s.zoo
/
gawk-src-2.13
/
awk.h
< prev
next >
Wrap
C/C++ Source or Header
|
1991-07-21
|
22KB
|
783 lines
/*
* awk.h -- Definitions for gawk.
*/
/*
* Copyright (C) 1986, 1988, 1989, 1991 the Free Software Foundation, Inc.
*
* This file is part of GAWK, the GNU implementation of the
* AWK Progamming Language.
*
* GAWK is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 1, or (at your option)
* any later version.
*
* GAWK is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GAWK; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* ------------------------------ Includes ------------------------------ */
#include <stdio.h>
#include <ctype.h>
#include <setjmp.h>
#include <varargs.h>
#include <time.h>
#include <errno.h>
#include <signal.h>
/* ----------------- System dependencies (with more includes) -----------*/
#ifndef VAXC
#include <sys/types.h>
#include <sys/stat.h>
#else /* VMS w/ Digital's "VAX C" compiler */
#include <types.h>
#include <stat.h>
#include <file.h> /* avoid <fcntl.h> in io.c */
#endif /*VAXC*/
#include "config.h"
#ifdef __STDC__
#define P(s) s
#define MALLOC_ARG_T size_t
#else
#define P(s) ()
#define MALLOC_ARG_T unsigned
#define volatile
#define const
#endif
#ifndef SIGTYPE
#define SIGTYPE void
#endif
#ifdef SIZE_T_MISSING
typedef unsigned int size_t;
#endif
#ifndef SZTC
#define SZTC
#define INTC
#endif
#ifdef STDC_HEADERS
#include <stdlib.h>
#include <string.h>
#ifdef NeXT
#include <libc.h>
#undef atof
#else
#if defined(atarist) || defined(VMS)
#include <unixlib.h>
#else
#include <unistd.h>
#endif /* atarist || VMS */
#endif /* Next */
#else /* STDC_HEADERS */
#include "protos.h"
#endif /* STDC_HEADERS */
#if defined(ultrix) && !defined(Ultrix41)
extern char * getenv P((char *name));
extern double atof P((char *s));
#endif
#ifdef sparc
/* nasty nasty SunOS-ism */
#include <alloca.h>
#ifdef lint
extern char *alloca();
#endif
#else /* not sparc */
#if (!defined(atarist)) && (!defined(NeXT)) && (!defined(alloca))
extern char *alloca();
#endif /* atarist */
#endif /* sparc */
#ifdef HAVE_UNDERSCORE_SETJMP
/* nasty nasty berkelixm */
#define setjmp _setjmp
#define longjmp _longjmp
#endif
/*
* if you don't have vprintf, but you are BSD, the version defined in
* vprintf.c should do the trick. Otherwise, try this and cross your fingers.
*/
#if defined(VPRINTF_MISSING) && !defined(DOPRNT_MISSING) && !defined(BSDSTDIO)
#define vfprintf(fp,fmt,arg) _doprnt((fmt), (arg), (fp))
#endif
#ifdef VMS
/* some macros to redirect to code in vms/vms_misc.c */
#define exit vms_exit
#define strerror vms_strerror
#define strdup vms_strdup
extern void exit P((int));
extern char *strerror P((int));
extern char *strdup P((const char *str));
# ifndef NO_TTY_FWRITE
#define fwrite tty_fwrite
#define fclose tty_fclose
extern size_t fwrite P((const void *,size_t,size_t,FILE *));
extern int fclose P((FILE *));
# endif
extern void vms_arg_fixup P((int *,char ***));
#endif /*VMS*/
#ifndef _MSC_VER
extern int errno; /* not necessary on many systems, but it can't hurt */
#endif
#define GNU_REGEX
#ifdef GNU_REGEX
#include "regex.h"
#include "dfa.h"
typedef struct Regexp {
struct re_pattern_buffer pat;
struct re_registers regs;
struct regexp dfareg;
int dfa;
} Regexp;
#define RESTART(rp,s) (rp)->regs.start[0]
#define REEND(rp,s) (rp)->regs.end[0]
#else /* GNU_REGEX */
#endif /* GNU_REGEX */
#ifdef atarist
#define read _text_read /* we do not want all these CR's to mess our input */
extern int _text_read (int, char *, int);
#endif
#ifndef DEFPATH
#define DEFPATH ".:/usr/local/lib/awk:/usr/lib/awk"
#endif
#ifndef ENVSEP
#define ENVSEP ':'
#endif
/* ------------------ Constants, Structures, Typedefs ------------------ */
#define AWKNUM double
typedef enum {
/* illegal entry == 0 */
Node_illegal,
/* binary operators lnode and rnode are the expressions to work on */
Node_times,
Node_quotient,
Node_mod,
Node_plus,
Node_minus,
Node_cond_pair, /* conditional pair (see Node_line_range) */
Node_subscript,
Node_concat,
Node_exp,
/* unary operators subnode is the expression to work on */
/*10*/ Node_preincrement,
Node_predecrement,
Node_postincrement,
Node_postdecrement,
Node_unary_minus,
Node_field_spec,
/* assignments lnode is the var to assign to, rnode is the exp */
Node_assign,
Node_assign_times,
Node_assign_quotient,
Node_assign_mod,
/*20*/ Node_assign_plus,
Node_assign_minus,
Node_assign_exp,
/* boolean binaries lnode and rnode are expressions */
Node_and,
Node_or,
/* binary relationals compares lnode and rnode */
Node_equal,
Node_notequal,
Node_less,
Node_greater,
Node_leq,
/*30*/ Node_geq,
Node_match,
Node_nomatch,
/* unary relationals works on subnode */
Node_not,
/* program structures */
Node_rule_list, /* lnode is a rule, rnode is rest of list */
Node_rule_node, /* lnode is pattern, rnode is statement */
Node_statement_list, /* lnode is statement, rnode is more list */
Node_if_branches, /* lnode is to run on true, rnode on false */
Node_expression_list, /* lnode is an exp, rnode is more list */
Node_param_list, /* lnode is a variable, rnode is more list */
/* keywords */
/*40*/ Node_K_if, /* lnode is conditonal, rnode is if_branches */
Node_K_while, /* lnode is condtional, rnode is stuff to run */
Node_K_for, /* lnode is for_struct, rnode is stuff to run */
Node_K_arrayfor, /* lnode is for_struct, rnode is stuff to run */
Node_K_break, /* no subs */
Node_K_continue, /* no stuff */
Node_K_print, /* lnode is exp_list, rnode is redirect */
Node_K_printf, /* lnode is exp_list, rnode is redirect */
Node_K_next, /* no subs */
Node_K_exit, /* subnode is return value, or NULL */
/*50*/ Node_K_do, /* lnode is conditional, rnode stuff to run */
Node_K_return,
Node_K_delete,
Node_K_getline,
Node_K_function, /* lnode is statement list, rnode is params */
/* I/O redirection for print statements */
Node_redirect_output, /* subnode is where to redirect */
Node_redirect_append, /* subnode is where to redirect */
Node_redirect_pipe, /* subnode is where to redirect */
Node_redirect_pipein, /* subnode is where to redirect */
Node_redirect_input, /* subnode is where to redirect */
/* Variables */
/*60*/ Node_var, /* rnode is value, lnode is array stuff */
Node_var_array, /* array is ptr to elements, asize num of
* eles */
Node_val, /* node is a value - type in flags */
/* Builtins subnode is explist to work on, proc is func to call */
Node_builtin,
/*
* pattern: conditional ',' conditional ; lnode of Node_line_range
* is the two conditionals (Node_cond_pair), other word (rnode place)
* is a flag indicating whether or not this range has been entered.
*/
Node_line_range,
/*
* boolean test of membership in array lnode is string-valued
* expression rnode is array name
*/
Node_in_array,
Node_func, /* lnode is param. list, rnode is body */
Node_func_call, /* lnode is name, rnode is argument list */
Node_cond_exp, /* lnode is conditonal, rnode is if_branches */
Node_regex,
/*70*/ Node_hashnode,
Node_ahash,
Node_NF,
Node_NR,
Node_FNR,
Node_FS,
Node_RS,
Node_FIELDWIDTHS,
Node_IGNORECASE,
Node_OFS,
Node_ORS,
Node_OFMT,
Node_CONVFMT
} NODETYPE;
/*
* NOTE - this struct is a rather kludgey -- it is packed to minimize
* space usage, at the expense of cleanliness. Alter at own risk.
*/
typedef struct exp_node {
union {
struct {
union {
struct exp_node *lptr;
char *param_name;
} l;
union {
struct exp_node *rptr;
struct exp_node *(*pptr) ();
Regexp *preg;
struct for_loop_header *hd;
struct exp_node **av;
int r_ent; /* range entered */
} r;
union {
char *name;
struct exp_node *extra;
} x;
short number;
unsigned char reflags;
# define CASE 1
# define CONST 2
# define